package cn.edu.sgu.www.mhxysy.service.prop.impl;

import cn.edu.sgu.www.mhxysy.entity.prop.FilterCondition;
import cn.edu.sgu.www.mhxysy.mapper.prop.FilterConditionMapper;
import cn.edu.sgu.www.mhxysy.service.prop.FilterConditionService;
import cn.edu.sgu.www.mhxysy.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class FilterConditionServiceImpl implements FilterConditionService {

    private final FilterConditionMapper filterConditionMapper;

    @Autowired
    public FilterConditionServiceImpl(FilterConditionMapper filterConditionMapper) {
        this.filterConditionMapper = filterConditionMapper;
    }

    @Override
    public void deleteById(String id) {
        filterConditionMapper.deleteById(id);
    }

    @Override
    public void save(FilterCondition filterCondition) {
        if (StringUtils.isNotEmpty(filterCondition.getId())) {
            filterConditionMapper.updateById(filterCondition);
        } else {
            filterCondition.setId(filterCondition.uuid());

            filterConditionMapper.insert(filterCondition);
        }
    }

    @Override
    public List<FilterCondition> selectConditions(Integer propId) {
        if (propId == null) {
            return new ArrayList<>();
        }

        QueryWrapper<FilterCondition> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("prop_id", propId);

        return filterConditionMapper.selectList(queryWrapper);
    }

}